/**
 * 项目入口文件
 */

import React from 'react';
import ReactDOM from 'react-dom';
import {createStore, applyMiddleware} from 'redux';
import {Provider} from 'react-redux';
import createRoutes from './route/Routes';
import createReducer from './flow/reducers';
import modelManager from './flow/ModelManager';

//加载model
import taskModel from './model/taskModel';
modelManager.useModel(taskModel);

const store = createStore(createReducer(), applyMiddleware(modelManager.getAsyncTaskMiddleware()));

function select(state) {
    return state
}

let currentValue;
function handleChange() {
    let previousValue = currentValue;
    currentValue = select(store.getState());

    if (previousValue !== currentValue) {
        // console.log(
        //     'from',
        //     previousValue,
        //     'to',
        //     currentValue
        // )
    }
}

store.subscribe(handleChange);

const Routes = createRoutes(store);

ReactDOM.render(
    <Provider store={store}>
        <Routes/>
    </Provider>,
    document.getElementById('root')
);
